package net.ustc.javamemcached.protocol;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

import org.jboss.netty.buffer.ChannelBuffer;

public class Protocol {
	// used for text protocol
	public static final Charset USASCII = Charset.forName("US-ASCII");

	public static enum ParameterType {
		INT, LONG, STRING, CHANNELBUFFER
	}
	
	public static class Parameter{
		private String parameterName;
		private ParameterType parameterType;
		private boolean repeated;
		private int index;
		public Parameter(String parameterName, ParameterType parameterType,
				boolean repeated, int index) {
			super();
			this.parameterName = parameterName;
			this.parameterType = parameterType;
			this.repeated = repeated;
			this.index = index;
		}
		public String getParameterName() {
			return parameterName;
		}
		public ParameterType getParameterType() {
			return parameterType;
		}
		public boolean isRepeated() {
			return repeated;
		}
		public int getIndex(){
			return index;
		}
	}

	private ChannelBuffer command;
	private Map<String, Parameter> parameters;
	private boolean needBackup;
	private boolean hasData;
	private boolean hasResponseData;
	private ChannelBuffer responseDate;

	public Protocol(ChannelBuffer command,
			Map<String, Parameter> parameters, boolean needBackup,
			boolean hasData, boolean hasResponseData) {
		this.command = command;
		this.parameters = parameters;
		this.needBackup = needBackup;
		this.hasData = hasData;
		this.hasResponseData = hasResponseData;
	}

	public ChannelBuffer getResponseDate() {
		return responseDate;
	}

	public void setResponseDate(ChannelBuffer responseDate) {
		this.responseDate = responseDate;
	}

	public boolean isHasData() {
		return hasData;
	}

	public void setHasData(boolean hasData) {
		this.hasData = hasData;
	}

	public boolean isNeedBackup() {
		return needBackup;
	}

	public void setNeedBackup(boolean needBackup) {
		this.needBackup = needBackup;
	}

	public boolean isHasResponseData() {
		return hasResponseData;
	}

	public void setHasResponseData(boolean hasResponseData) {
		this.hasResponseData = hasResponseData;
	}

	public ChannelBuffer getCommand() {
		return command;
	}

	public Map<String, Parameter> getParameters() {
		return parameters;
	}
}
